/* MusicNet Alignment Tool
 *
 * Copyright (c) 2010 Joe Lambert
 * 
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *  
 */

/** section: alignment
 * class InfoView
 * 
 * View responsible for displaying the extended metadata
 **/


var InfoView = Class.create({
	initialize: function()
	{
		this.surface = Builder.node('div', {id: 'infoview'});
		
		document.observe('information:view', function(event) { this.loadView(event.memo) }.bindAsEventListener(this));
	},

/**
 * InfoView#loadView(ids) -> null
 * - ids (Array): The item IDs to load
 *  
 * Load information about the provided IDs
 **/
	
	loadView: function(ids)
	{
		var ids_string = "";
		ids.each(function(id) {
			ids_string += "&id[]="+id;
		});
		
		this.setLoading();
		
		new Ajax.Request(window.location.pathname+"ajax/metadata", {
			method: 'get',
			parameters: ids_string,
			onSuccess: function(transport) {
				this.surface.update(transport.responseText);
			}.bind(this)
		});
	},

/**
 * InfoView#setLoading(loading) -> null
 * - loading (Boolean): Whether to hide/show the loading indicator
 *  
 * Show/hide the loading indicator
 **/
		
	setLoading: function(loading)
	{
		if(Object.isUndefined(loading))
			loading = true;
			
		if(loading)
		{
			this.surface.update(Builder.node('div', {className: 'loading'}, 'Loading'));
		}
		else
		{

		}
	},

/**
 * InfoView#getSurface() -> null
 *  
 * Gets the drawing surface for this object
 **/
	
	getSurface: function()
	{
		return this.surface;
	}
});